home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / a11_3a.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  2.6 KB  |  89 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 11.3 (Jacobi Iteration for Eigenvalues and Eigenvectors).
  9. % Section    11.3,    Jacobi's Method, Page 571
  10. echo on; clc; format long; hold off; clear
  11.  
  12. % JACOBI METHOD FOR FINDING EIGEN-PAIRS
  13.  
  14. % Assume that A is an n by n symmetric real matrix, thus
  15.  
  16. % it has a full set of eigenvectors  V , V  ,..., V .
  17. %                                     1   2        n
  18.  
  19. % The original Jacobi`s method of iteration is used
  20.  
  21. %  to find all of the eigen-pairs.
  22.  
  23. % Remark. jacobi1.m is used for Algorithm 11.3a
  24.  
  25. pause % Press any key to continue.
  26.  
  27. clc;
  28. %             JACOBI`S  METHOD FOR EIGENVECTORS
  29. %      Assume that A is an n by n real symmetric matrix.
  30. % Then A has a full set of eigenvectors: V , V ,..., V
  31. %                                         1   2       n
  32. % Jacobi`s method of iteration is used to find all the
  33. % eigenvalues and eigenvectors of  A.   Let  A = A , 
  34. %                                                 1
  35. % and construct a sequence of orthogonal matrices
  36. %                     T
  37. % {R }  where  D  =  R  A  R    and  { D  } converges
  38. %   j           j     j  j  j           j
  39.  
  40. %  to the diagonal matrix D, of eigenvalues, and
  41.  
  42. % {V  = R R ...R } converges to the matrix of eigenvectors.
  43. %   j    1 2    j
  44.  
  45. pause % Press any key to continue.
  46.  
  47. clc;
  48. %     We use Jacobi`s original strategy for selecting the off
  49. % diagonal element to annihilate in the construction process.
  50.  
  51. % Select p,q so that   |a  |  =  max |a  |.
  52. %                        pq      i<j   ij  
  53.  
  54. %      For each sweep throughout the matrix, the computed
  55. % value t is the [R.M.S.] average of the diagonal elements
  56. % of A.  The user must supply the error tolerance for
  57. % annihilating the off diagonal elements
  58.  
  59. %        |d   |  >  t*epsilon       for all  q > p.
  60. %          p,q
  61.  
  62. pause % Press any key to continue.
  63.  
  64. clc;
  65. % Place the matrix in  A
  66.  
  67. % Place the tolerance in   epsilon
  68.  
  69. A = [ 8   -1    3   -1;
  70.      -1    6    2    0;
  71.       3    2    9    1;
  72.      -1    0    1    7];
  73.  
  74. epsilon = 1e-16;
  75.  
  76. [V,D] = jacobi1(A,epsilon,1);
  77.  
  78. pause % Press any key to continue.
  79.  
  80. clc;
  81. Mx1 = 'Implementation of the original Jacobi method.';
  82. Mx2 = 'The matrix  A  is:';
  83. Mx3 = 'The eigenvalues of  A  are:';
  84. Mx4 = 'The eigenvectors of  A  are:';
  85. clc,echo off,diary output,..
  86. disp(''),disp(Mx1),disp(''),disp(Mx2),disp(A),
  87. disp(Mx3),disp(diag(D)),disp(Mx4),disp(V),...
  88. diary off,echo on
  89.